import React from "react";
import {Image, TextInput, View} from "react-native";
import {TextInputPropTypes} from 'deprecated-react-native-prop-types';

import PropTypes from "prop-types";

class IconInput extends React.PureComponent {

    static propTypes = {
        leftIcon: PropTypes.object,
        placeholder: PropTypes.string,
        inputStyle: TextInputPropTypes.style,
        value: PropTypes.string,
        editable: PropTypes.bool,
        onChangeText: PropTypes.func,
        keyboardType: PropTypes.string,
        rightView: PropTypes.object,
        secureTextEntry: PropTypes.bool,
        returnKeyType: PropTypes.string
    };


    render() {
        const {style} = {...this.props};
        const viewStyle = [
            {
                flexDirection: "row",
                alignItems: "center",
                paddingRight: 5,
                paddingTop: 0,
                paddingLeft: 5,
                paddingBottom: 0,
                borderBottomWidth: 1,
                borderBottomColor: "#d7d7d7"
            },
            style
        ];
        let inputStyle = [this.props.inputStyle, {flex: 1, borderWidth: 0}];
        return <View {...this.props} style={viewStyle}>
            {this.props.leftIcon}
            <TextInput placeholder={this.props.placeholder} style={inputStyle} clearButtonMode='while-editing'
                       value={this.props.value} onChangeText={this.props.onChangeText}
                       returnKeyType={this.props.returnKeyType}
                       keyboardType={this.props.keyboardType}
                       secureTextEntry={this.props.secureTextEntry}/>
            {this.props.rightView}
        </View>;
    }
}

export default IconInput;
